<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
	 <link rel="stylesheet" href="${pageContext.request.contextPath }/css/editTablestyles.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath }/webjars/jquery/1.12.4/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/listTable.js"></script>
	<link rel="stylesheet" />
	<link rel="stylesheet" href="css/Site.css" />
	<link rel="stylesheet" href="css/zy.all.css" />
	<link rel="stylesheet" href="css/font-awesome.min.css" />
	<link rel="stylesheet" href="css/amazeui.min.css" />
	 <link rel="stylesheet" href="css/admin.css" />
</head>
<body>
	<div class="dvcontent">

			<div>
				
				<div class="tabs">
					<div class="hd">
						<ul>
							<li class="on" style="box-sizing: initial;-webkit-box-sizing: initial;">会员管理</li>
						</ul>
					</div>
					<div class="bd">
						<ul style="display: block;padding: 20px;">
							<li>
								<!--分页显示角色信息 start-->
								<div id="dv1">
									<form action="" method="post">
									<table  class="querytable"  style="margin-bottom:  35px">
										<tr>
											<th class="textright">用户名：</th>
											<td class="textleft">
												<input type="text" name="username" />
											</td>
											<th class="textright">用户角色：</th>
											<td class="textleft">
												<select name="userroles" >
													<option value="">--请选择--</option>
													<option value="1">管理员</option>
													<option value="2">普通用户</option>
												</select>
											</td>
										</tr>
										<tr>
											<td colspan="4" align="center">
												<input type="button" value="查询" />
											</td>
										</tr>
									</table>	
								
									<table class="table" id="tbRecord">
											<tr>
												<th>用户ID</th>
												<th>用户名</th>
												<th>用户角色</th>
												<th>昵称</th>
												<th>电话</th>
												<th>编辑</th>
												<th>删除</th>
											</tr>
											<c:choose>
												<c:when test="${empty ulist }">
													<tr>
														<td colspan="7" style="color: red;"><b>对不起，没有查询到相关记录！</b></td>
													</tr>
												</c:when>
												<c:otherwise>
													<c:forEach items="${ulist }" var="ulist">
														<tr>
															<td>${ulist.userid }</td>
															<td>${ulist.username }</td>
															<td>
																<c:if test="${ulist.userroles eq '1' }">管理员</c:if>
																<c:if test="${ulist.userroles eq '2' }">普通用户</c:if>
															</td>
															<td>${ulist.nickname }</td>
															<td>${ulist.telphone }</td>
															<td class="edit"><i class="icon-edit bigger-120"></i><a href="user.action?methodName=toUpdateUser&userid=${ulist.userid }">编辑</a></td>
															<td class="delete"><i class="icon-trash bigger-120"></i><a href="javascript:void(0);" class="ajaxDelete"  tbuser="${ulist.userid }">删除</a></td>
														</tr>
												</c:forEach>
												</c:otherwise>
										</c:choose>
										<tr>
									<td colspan="7">
				
										<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
											<tr>
												<td width="50%">
				
													<span class="right-font08">共 ${page.totalPages} 页 | 第 ${page.pageNumber} 页</span>
												</td>
												<td width="49%" align="right">
													<span class="right-font08"> <a href="javascript:toPage(${1})">[  首页  </a> <c:if test="${page.pageNumber>1}">
															<a href="javascript:toPage(${page.pageNumber-1})">上一页</a>
														</c:if> 跳转到第<select name="pageNumber" onchange="gotoSelectedPage();">
															<c:forEach begin="1" end="${page.totalPages}" step="1" var="pageIndex">
																<c:choose>
																	<c:when test="${pageIndex eq page.pageNumber}">
																		<option value="${pageIndex}" selected="selected">
																			${pageIndex}
																		</option>
																	</c:when>
																	<c:otherwise>
																		<option value="${pageIndex}">
																			${pageIndex}
																		</option>
																	</c:otherwise>
																</c:choose>
															</c:forEach>
														</select> <c:if test="${page.pageNumber<page.totalPages}">
															<a href="javascript:toPage(${page.pageNumber+1})">下一页</a>
														</c:if> <a href="javascript:toPage(${page.totalPages})">末页]</a> </span>
												</td>
				
											</tr>
										</table>
				
									</td>
								</tr>

				<!-- 分页结束 -->
									</table>
									</form>
								</div>
								<!--分页显示角色信息 end-->
							</li>
						</ul>
					</div>
				</div>	
			</div>
	</div>	
</body>
<script type="text/javascript">
$(function() {
	$("input[type='button']").click(function() {
		$("form").attr("action","user.action?methodName=doListUser").submit();
	});
	$("select[name='pageNumber']").change(function() {
		$("form").attr("action","user.action?methodName=doListUser").submit();
	});
	var urows="${param.urows}";
	if(urows>0){
		alert("修改成功！");
	}else{
		alert("修改失败！")
	}
});

</script>
<script type="text/javascript">
function toPage(pNumber) {
	$("form").attr("action","user.action?methodName=doListUser&pageNumber="+pNumber).submit();
}
</script>
<script type="text/javascript">
$(function() {
	$(".ajaxDelete").click(function() {
		if(confirm('确认删除用户？')){
			var id=$(this).attr("tbuser");
			$.ajax({
				type:"post",
				url:"user.action?methodName=ajaxDeleteUser",
				data:{"userid":id},
				success:function(returnData){
					if(returnData!=null){
						alert("删除成功！");
						$("[tbuser="+id+"]").parent().parent().remove();
					}else{
						alert("删除失败！")
					}
				}
			});
		}
		
	})	;
});
</script>
</html>
